package com.lomoye.easy.backend;

import us.codecraft.webmagic.Spider;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 2020/4/23 17:50
 * yechangjun
 */
public class SpiderHolder {

    //正在运行的爬虫对象的容器
    private static Map<String/*jobId*/, Spider> spiderContainer = new ConcurrentHashMap<>();

    //放入爬虫
    public static Spider putSpider(Spider spider) {
        return spiderContainer.putIfAbsent(spider.getUUID(), spider);
    }

    //获取爬虫
    public static Spider getSpider(String uuid) {
        return spiderContainer.get(uuid);
    }

    //删除爬虫
    public static Spider removeSpider(String uuid) {
        return spiderContainer.remove(uuid);
    }

}
